const tokens = {
  admin: 'admin-token',
  editor: 'editor-token',
}

const loginUsers = {
  'admin-token': {
    name: 'Super Admin',
    permissionList: ['admin:*'],
  },
  'editor-token': {
    name: 'Normal Editor',
    permissionList: ['admin:user:list', 'admin:user:add'],
  },
}

export default [
  // user login
  {
    url: '/mock/login',
    type: 'post',
    response: (config) => {
      const { username } = config.body
      const token = tokens[username]

      // mock error
      if (!token) {
        return {
          code: 500,
          message: '账号或密码错误',
        }
      }
      return {
        code: 200,
        data: token,
      }
    },
  },
  // user info
  {
    url: '/mock/userInfo',
    type: 'get',
    response: (config) => {
      // authorization: 'admin-token',
      const { authorization } = config.headers
      const info = loginUsers[authorization]
      // mock error
      if (!info) {
        return {
          code: 401,
          message: '请先登录',
        }
      }
      return {
        code: 200,
        data: info,
      }
    },
  },
  // user logout
  {
    url: '/mock/logout',
    type: 'get',
    response: (config) => {
      return {
        code: 200,
        data: 'success',
      }
    },
  },
]
